package example.db;

import java.sql.*;

public class DerbyExample {
    public static void main(String[] args) {
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;

        try {
            // 连接到Derby数据库
            conn = DriverManager.getConnection("jdbc:derby:/path/to/your/derby/database");

            // 创建Statement对象
            stmt = conn.createStatement();

            // 执行查询
            rs = stmt.executeQuery("SELECT * FROM your_table");

            // 处理结果集
            while (rs.next()) {
                int id = rs.getInt("id");
                String name = rs.getString("name");
                System.out.println("ID: " + id + ", Name: " + name);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                // 关闭连接和Statement对象
                if (rs != null) rs.close();
                if (stmt != null) stmt.close();
                if (conn != null) conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
